<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/commons/jsp/taglibs.jsp"%>
<%@taglib uri="http://www.framework.com/taglib" prefix="frame"%>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<script type="text/javascript" src="${ctx}/commons/js/uploadify/jquery.uploadify.min.js"></script>
<link type="text/css" href="${ctx}/commons/js/uploadify/uploadify.css" rel="stylesheet"></link>
<style type="text/css">
	li{
		padding-top:8px;
	}
	.st{
	 display:none;
	}
</style>
<script type="text/javascript">
     var requestUrl="http://${basePath}:${port}${ctx}/business/projectmanage/bidder/shotInput?projectId=${project.id}";
</script>
<form name="addProjectsDataForm" id="addProjectsDataForm" method="post" action="${ctx}/business/projectmanage/bidder/doSubmitShot" 
	saveaction="${ctx}/business/projectmanage/bidder/saveShot">
	<input type="hidden" name="id" id="id" value="${pb.id}"/>
	<input type="hidden" name="projectId" id="projectId" value="${project.id}"/>
	<input type="hidden" name="budgetMenuData" id="budgetMenuData" value=""/>
	
	<div class="easyui-panel" data-options="border:true,title:'投标报价'" style="padding:6px;margin-bottom: 6px;">
		<table class="infoTable">
		<tr>
			<th align="right" width="15%">
			投标报价
			<c:if test="${project.bidType==0 }">
			(元)
			</c:if>
			<c:if test="${project.bidType==1 }">
			(%)
			</c:if>
			</th>
			<td colspan="3">
				<input id="bidAmount" name="bidAmount" oninput="bidAmountBigOnblus();" onpropertychange="bidAmountBigOnblus();" onkeyup="bidAmountBigOnblus();"  style="width:180px;" maxlength="20" class="easyui-validatebox" prompt="" data-options="required:true,validType:['priceDecimal']" value="<fmt:formatNumber value="${pb.bidAmount }" type="currency" pattern="0.00#"/>"/>
				<c:if test="${project.bidType==0 }">
				 <span id="bidAmountBig" ></span>
				</c:if>
			</td>
		</tr>
		<tr>
			<th align="right" width="15%">法人代表或本项目委托人姓名</th>
			<td >
				<input id="consignor" class="easyui-validatebox" name="consignor" style="width:180px;"  prompt="" data-options="required:true" style="width:180px;" maxlength="20" value="${pb.consignor }"/>
			</td>
			<th align="right" width="15%">法人代表或本项目委托人身份证号</th>
			<td>
				<input id="consignorIdCard" class="easyui-validatebox" name="consignorIdCard" style="width:180px;"  prompt="" data-options="required:true,validType:['card']"  style="width:180px;" maxlength="20" value="${pb.consignorIdCard }"/>
			</td>
		</tr>
		<tr>
			<th align="right" width="15%">法人代表或本项目委托人联系方式</th>
			<td>
				<input id="consignorPhone" name="consignorPhone" class="easyui-validatebox"  style="width:180px;"  prompt=""  data-options="required:true,validType:['isNull']" style="width:180px;" maxlength="20" value="${pb.consignorPhone }"/>
			</td>
		</tr>
		
	</table>
	</div>
	
	<div class="easyui-panel" data-options="border:true,title:'响应文件'" style="padding:6px;margin-bottom: 6px;">
		<table class="infoTable">
			<tbody>
				<c:forEach var="response" items="${fn:split(project.responseFile,'@')}" varStatus="sta">
					<c:if test="${response!='-'}">
						<tr>
							<td style="border-left: none;background-color: #EDF4FB;" align='left' width="30%">${response } </td>
							
							<td style="border-right: none" width="35%">
								<span id="fileQueue${sta.index+1 }" class="fileQueue" flag="${sta.index+1 }" style="margin: 10px 0px 0px 10px">
									<input type="file" name="uploadify" class="uploadify" id="uploadify${sta.index+1 }" data-options="required:true"/>
									<p style="color: #aaaaaa;width: auto">
									1、按住Ctrl可选择多个文件上传;<br/>
									2、可上传*.pdf;类型文件<br/>
									</p><br>
									<c:if test="${response eq '竞价内容（必须与报价表内容（品名、品牌与型号、数量、单价、合计）一致，具体填写详见竞价内容简表'}">
										<div><a class="easyui-linkbutton" style="background-color: #5F85B6;" href="${ctx }/file_resource/shot-table-table.doc" target="_bank">竞价内容模板</a></div>
									</c:if>
								</span>
							</td>
							<td style="border-left: none" colspan="3" width="55%">
								<c:forEach items="${resList}" var="res">
									<c:if test="${res.functionFlog==sta.index+1}">
										<div><a class="easyui-linkbutton" href="javascript:showOpenFile('${ctx }','${res.id}',requestUrl);">${res.oldName}</a> <span style="cursor: pointer;" onclick="deleteFile(this,'${res.id}');"><img src="${ctx }/commons/themes/icons/cancel.png"/></span></div>
									</c:if>
								</c:forEach>
							</td>
						</tr>
					</c:if>
				</c:forEach>
		</tbody>
		</table>
	</div>
</form>
<script type="text/javascript">
	
	$(function(){
	   // parent.$('#addEntityBt').hide();
		var resIds = "";
		<c:forEach items="${resList}" var="res">
		resIds += ",${res.id}";
		</c:forEach>
		$('#budgetMenuData').val(resIds);



		$(".uploadify").each(function() {
			upload=$(this).parent().parent().parent().find(".fileName");
			fileQueue=$(this).parent().parent().parent().find(".fileQueue");
			//alert(upload.val());
			$(this).uploadify({
				'height'        : 27,   
	            'width'         : 80,    
	            'buttonText'    : '选择附件',
	            'queueID': fileQueue.val(),//队列的ID
	            'queueSizeLimit':5,// 附件附列长度
				'swf': '${ctx}/commons/js/uploadify/uploadify.swf',
				'uploader':'${ctx}/business/projectmanage/upload;jsessionid=${pageContext.session.id}',// 上传时请求的后台处理的controller
				'cancelImg': '${ctx}/commons/js/uploadify/uploadify-cancel.png',
				'method':'post',  
				'folder': '',
				'preventCaching' : true,
				'fileTypeExts' :'*.pdf;',
				'auto': true,
				'multi': true,//是否可多选
				'removeCompleted' : false,
				'successTimeout' : 55555,
				'onUploadSuccess':function(file, data, response){
					$('#' + file.id).find('.data').html(' 上传完毕');
					$('#budgetMenuData').val($('#budgetMenuData').val() + "," + data);
					//alert("ww"+$('#' + file.id).parent().html());
					var cancel=$('.fileQueue .uploadify-queue-item[id="' + file.id + '"]').find(".cancel a");
					if (cancel) {
					   cancel.attr("rel", data);
					   cancel.click(function () {
						   var cancelData = cancel.attr("rel");
			               var  budgetMenuData = $('#budgetMenuData').val();
			               var index = budgetMenuData.indexOf(","+cancel.attr("rel"))
			               if(index != -1){
			            	   budgetMenuData = budgetMenuData.replace(","+cancelData,"");
			            	   $('#budgetMenuData').val(budgetMenuData);
			               }
					   });
					}
				},
				'onUploadStart':function(file){
					//alert("ww"+$('#' + file.id).parent().parent().find(".uploadify").attr("id"));
					var uploadId=$('#' + file.id).parent().parent().find(".uploadify").attr("id");
					//var params=$('#' + file.id).parent().parent().parent().parent().find(".fileName").val();
					var functionFlog=$('#' + file.id).parent().parent().parent().parent().find(".fileQueue").attr("flag");
			        $("#"+uploadId).uploadify("settings","formData",{"functionFlog":functionFlog});
				},
				'onSelectError':function(file, errorCode, errorMsg){
					//alert(errorCode);
					switch(errorCode) {
						case -110:
							//this.queueData.errorMsg="文件 ["+file.name+"] 大小超出系统限制的"+$('#file_upload').uploadify('settings','fileSizeLimit')+"大小！";
							this.queueData.errorMsg='所选文件大小超出系统限制!';
							break;
						case -120:
							//this.queueData.errorMsg="文件 ["+file.name+"] 大小异常！"
							this.queueData.errorMsg='所选文件大小异常!';
							break;
						case -130:
							//this.queueData.errorMsg="文件 ["+file.name+"] 类型不正确！"
							this.queueData.errorMsg='所选文件类型不正确!';
							break;
					}
				},
				'onCancel' : function(file){
					//alert(file);
				}
			});
		});
		
	});


	//============
	function deleteFile(v,resId){
		var parent = v.parentNode;
		parent.parentNode.removeChild(parent);
		var  budgetMenuData = $('#budgetMenuData').val();
        var index = budgetMenuData.indexOf(","+resId)
        if(index != -1){
     	   budgetMenuData = budgetMenuData.replace(","+resId,"");
     	   $('#budgetMenuData').val(budgetMenuData);
        }

        //删除数据库中的文件信息
        $.ajax({
			type : "post",
			url : "${ctx}/business/projectmanage/deleteFile?resId="+resId,
			data : top.$("#addProjectsDataForm").serialize(),
			success : function(data){
				
			},
			error : function(data){
				alert("错误");
			}
		});
	}
	
	/*
	* 显示大写金额
	*/
	function bidAmountBigOnblus(){
		var bidAmount=$("#bidAmount").val();//获取报价值(小写)
		var bidAmountBig=convertCurrency(bidAmount);//转化为大写
		$("#bidAmountBig").text(bidAmountBig);
	}
	
</script>